package com.songkun.template.refrofit;

import android.text.TextUtils;

import com.songkun.template.utils.StringUtil;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;


/**
 * 公共参数
 */
public class QueryParameterInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        HttpUrl.Builder newBuilder = originalRequest.url().newBuilder();

        String loginToken = StringUtil.getLoginToken();

        if (!TextUtils.isEmpty(loginToken)) {
            newBuilder.addQueryParameter("rt", "5");
        }

        HttpUrl modifiedUrl = newBuilder.build();

        Request request = originalRequest.newBuilder().url(modifiedUrl).build();
        return chain.proceed(request);
    }
}
